import java.io.File;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author WangYan
 * @description:
 * @date 2022/1/26 13:48
 */
public class Main {
    static String inputPath = "C:\\Users\\EDZ\\Desktop\\已取点省份-高德坐标";
    static String outputPath = "C:\\Users\\EDZ\\Desktop\\已取点省份-84坐标";

    public static void main(String[] args) throws Exception {
        File[] files = null;
        File file = new File(inputPath);
        if (file.isDirectory()) {
            //多个文件
            files = file.listFiles();
        } else {
            //单个文件
            files = new File[]{file};
        }

        for (File csv : files) {
            convertCsv(csv);
        }
    }

    private static void convertCsv(File csv) throws Exception {
        System.out.println("读取 csv 文件");
        List<String> lines = CsvToListUtil.getLines(csv, "UTF-8");
//        List<String> lines = CsvToListUtil.getLines(csv, "GBK");
        List<LinkedHashMap<String, Object>> data = CsvToListUtil.parseList(lines);

        System.out.println("处理数据");
        for (LinkedHashMap<String, Object> vo : data) {
            Map<String, Double> stringDoubleMap = LocationUtil.gcj02_To_Gps84(String.valueOf(vo.get("纬度")), String.valueOf(vo.get("经度")));
            if (stringDoubleMap != null) {
                vo.put("84经度", stringDoubleMap.get("lon"));
                vo.put("84纬度", stringDoubleMap.get("lat"));
            }
        }

        //生成 csv 文件
        System.out.println("生成 csv 文件");
        CsvToListUtil.toCSVFile(outputPath + "\\" + csv.getName(), data);
    }


}
